package com.yazi.mxz.common.service.impl;


import javax.annotation.Resource;

import com.myframework.smhj.hibernate.dao.BasicService;
import com.myframework.smhj.hibernate.dao.Dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yazi.mxz.common.db.dao.MaterialDao;
import com.yazi.mxz.common.entity.ValueFactory;
import com.yazi.mxz.common.entity.beans.Cook;
import com.yazi.mxz.common.entity.beans.Material;
import com.yazi.mxz.common.service.MaterialService;

@Service("materialService")
public class MaterialServiceImpl extends BasicService<Material> implements MaterialService {
	private static Logger log = LoggerFactory.getLogger(MaterialServiceImpl.class);
	
	@Resource
	MaterialDao materialDao;
	
	@Override
	protected Dao<Material> getDao() {
		return materialDao;
	}
	
	@Override
	public Material add(Material material, Cook cook) {
		log.debug("add：name={}", material.getName());
		material = ValueFactory.validate(material);
		material.setCook(cook);
		material.setMaterialId(null);
		return materialDao.persist(material);
	}

}
